package com.fenghen.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.fenghen.config.CodeGenerator;
import com.fenghen.config.Result;
import com.fenghen.entity.CodeGeneratorConfig;
import com.fenghen.entity.Test;
import com.fenghen.service.CodeGeneratorService;
import com.fenghen.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("/test")
public class TestController {

    @Autowired
    private TestService testService;

    @Autowired
    private CodeGeneratorService codeGeneratorService;

    @GetMapping()
    public Result test() {
        List<Test> list = testService.list();
        return Result.ok(list);
    }

    @PostMapping("/update")
    public Result updatetest(@RequestBody Test test) {
        testService.updatetest(test);
        return Result.ok();
    }

    @GetMapping("/1")
    public Test test1() {
        LambdaQueryWrapper<Test> testLambdaQueryWrapper = new LambdaQueryWrapper<>();
        testLambdaQueryWrapper.eq(Test::getPetage, 2.7);
        Test one = testService.getOne(testLambdaQueryWrapper);
        return one;
    }

    @PostMapping("/generate-code")
    public Result generateCode(@RequestBody CodeGeneratorConfig config) {
        codeGeneratorService.generateCode(config);
        return Result.ok("Code generation initiated successfully");
    }
}
